package nl.memedefense.application;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import nl.memedefense.core.GameMaster;
import nl.memedefense.screen.GameScreen;
import nl.memedefense.screen.WelcomeScreen;

/**
 * Main entry point for the application. Responsible for orchestrating flow of the screens.
 */
public class MemeDefense implements ApplicationListener {

    private Screen currentScreen;
    private GameMaster gameMaster;

    /**
     * {@inheritDoc}
     */
    @Override
    public void create() {
        currentScreen = new WelcomeScreen();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void resume() {

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void render() {
        if (currentScreen instanceof WelcomeScreen) {
            if (Gdx.input.isTouched()) {
                currentScreen.dispose();

                gameMaster = new GameMaster();
                currentScreen = new GameScreen(gameMaster.getLevel());
            }
        }
        currentScreen.render(Gdx.graphics.getDeltaTime());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void resize(int width, int height) {
        currentScreen.resize(width, height);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void pause() {

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void dispose() {
        currentScreen.dispose();
    }
}
